﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class Mem
    {
        private readonly Chain.IDAL.Mem dal = new Chain.IDAL.Mem();

        public int Add(Chain.Model.Mem model)
        {
            int num = this.Exists(model.MemID, model.MemCard, model.MemMobile, model.MemCardNumber);
            if (num != 1)
            {
                return num;
            }
            return this.dal.Add(model);
        }

        public int AddCustomField(string MemCard, Hashtable customhash)
        {
            return this.dal.AddCustomField(MemCard, customhash);
        }

        public int AddMemFirst(Chain.Model.Mem model)
        {
            int num = this.Exists(model.MemID, model.MemCard, model.MemMobile, model.MemCardNumber);
            if (num != 1)
            {
                return num;
            }
            return this.dal.AddMemFirst(model);
        }

        public bool ChangeCard(Chain.Model.Mem modelMem, string newMemCard, string newPwd)
        {
            return this.dal.ChangeCard(modelMem, newMemCard, newPwd);
        }

        public Chain.Model.Mem CheckMemPwd(string strAccount, string strPassword)
        {
            DataTable dt = this.dal.CheckMemPwd(strAccount, strPassword);
            if (dt.Rows.Count > 0)
            {
                return this.DataTableToList(dt)[0];
            }
            return null;
        }

        public bool ClearMemberPoint(int MemID)
        {
            return this.dal.ClearMemberPoint(MemID);
        }

        public List<Chain.Model.Mem> DataTableToList(DataTable dt)
        {
            List<Chain.Model.Mem> list = new List<Chain.Model.Mem>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.Mem item = this.dal.DataRowToModel(dt.Rows[i]);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        public bool Delete(int MemID)
        {
            return this.dal.Delete(MemID);
        }

        public bool DeleteList(string MemIDlist)
        {
            return this.dal.DeleteList(MemIDlist);
        }

        public int DrawMoney(int memID, decimal money)
        {
            return this.dal.DrawMoney(memID, money);
        }

        public bool ExeclDataInput(ArrayList sqlArray)
        {
            return this.dal.ExeclDataInput(sqlArray);
        }

        public int ExistPwd(int MemID, string oldPwd)
        {
            return this.dal.ExistPwd(MemID, oldPwd);
        }

        public bool Exists(int MemID)
        {
            return this.dal.Exists(MemID);
        }

        public int Exists(int MemID, string MemCard, string MemMobile, string MemCardNumber)
        {
            return this.dal.Exists(MemID, MemCard, MemMobile, MemCardNumber);
        }

        public bool ExistsMemCard(string MemCard)
        {
            return this.dal.ExistsMemCard(MemCard);
        }

        public int ExpenseUpdateMem(int memID, decimal dclMemMoney, decimal memConsumeMoney, int point, DateTime dtime, int count)
        {
            return this.dal.ExpenseUpdateMem(memID, dclMemMoney, memConsumeMoney, point, dtime, count);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetBirthdayList(int day, int shopID)
        {
            return this.dal.GetBirthdayList(day, shopID);
        }

        public DataSet GetBirthdayList(int day, int shopID, int count)
        {
            return this.dal.GetBirthdayList(day, shopID, count);
        }

        public DataSet GetDataByTime(DateTime starttime, DateTime endtime, string strwhere)
        {
            return this.dal.GetDataByTime(starttime, endtime, strwhere);
        }

        public DataSet GetItemAll(int MemID)
        {
            return this.dal.GetItemAll(MemID);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListS(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListS(PageSize, PageIndex, strWhere, out resCount);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public DataTable GetMemAdressBymencard(string MemCard)
        {
            return this.dal.GetMemAdressBymencard(MemCard);
        }

        public static string GetMemBirthday(DateTime birthday)
        {
            if (((birthday.Year == 0x76c) && (birthday.Month == 1)) && (birthday.Day == 1))
            {
                return "";
            }
            return birthday.ToString("yyyy-MM-dd");
        }

        public DataSet GetMemBirthday(int day)
        {
            return this.dal.GetMemBirthday(day);
        }

        public Chain.Model.Mem GetMemByWeiXinCard(string weiXinCard)
        {
            return this.dal.GetMemByWeiXinCard(weiXinCard);
        }

        public DataSet GetMemConsumeMoney(string strWhere)
        {
            return this.dal.GetMemConsumeMoney(strWhere);
        }

        public int GetMemCount(string strWhere)
        {
            return this.dal.GetMemCount(strWhere);
        }

        public DataSet GetMemExpense(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetMemExpense(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetMemExpense(int PageSize, int PageIndex, out int resCount, string strTime, params string[] strWhere)
        {
            return this.dal.GetMemExpense(PageSize, PageIndex, out resCount, strTime, strWhere);
        }

        public DataSet GetMemExpenseDetail(string strWhere)
        {
            return this.dal.GetMemExpenseDetail(strWhere);
        }

        public DataSet GetMemExpenseToWeiXin(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetMemExpenseToWeiXin(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.Mem GetMemInfoByMobile(string Mobile)
        {
            return this.dal.GetMemInfoByMobile(Mobile);
        }

        public DataSet GetMemPast(int day)
        {
            return this.dal.GetMemPast(day);
        }

        public DataSet GetMemPastTime(string strSql, int shopID)
        {
            return this.dal.GetMemPastTime(strSql, shopID);
        }

        public DataSet GetMemPastTime(string strSql, int shopID, int count)
        {
            return this.dal.GetMemPastTime(strSql, shopID, count);
        }

        public DataTable getMemPayList(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.getMemPayList(PageSize, PageIndex, strWhere, out resCount);
        }

        public DataSet GetMemPointReset(string strSql, int type)
        {
            return this.dal.GetMemPointReset(strSql, type);
        }

        public DataSet GetMemPointReset(string strSql, int type, int count)
        {
            return this.dal.GetMemPointReset(strSql, type, count);
        }

        public DataTable getMemRecommend(object memid)
        {
            return this.dal.getMemRecommend(memid);
        }

        public DataTable getMemRecommendList(int MemID)
        {
            return this.dal.GetMemRecommendList(MemID);
        }

        public Chain.Model.Mem GetMemWeiXinCardModel(string strMemWeiXinCard, string strAttributes)
        {
            return this.dal.GetMemWeiXinCardModel(strMemWeiXinCard, strAttributes);
        }

        public Chain.Model.Mem GetModel(int MemID)
        {
            return this.dal.GetModel(MemID);
        }

        public Chain.Model.Mem GetModel(string memCard)
        {
            return this.dal.GetModel(memCard);
        }

        public Chain.Model.Mem GetModelByMemCard(string MemCard)
        {
            return this.dal.GetModelByMemCard(MemCard);
        }

        public Chain.Model.Mem GetModelByMemMobile(string Mobile)
        {
            return this.dal.GetModelByMemMobile(Mobile);
        }

        public DataTable GetModelDetail(params string[] strWhere)
        {
            return this.dal.GetModelDetail(strWhere);
        }

        public List<Chain.Model.Mem> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetPointRankList(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetPointRankList(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public DataSet IsCanDelMem(int MemID)
        {
            return this.dal.IsCanDelMem(MemID);
        }

        public int MemCountUpdateMem(int memID, decimal dclMemMoney, int point)
        {
            return this.dal.MemCountUpdateMem(memID, dclMemMoney, point);
        }

        public int MemRegister(string CardID, string LevelID, int userid, int shopid, string phone, string name)
        {
            return this.dal.MemRegister(CardID, LevelID, userid, shopid, phone, name);
        }

        public int SecuritySettings(int intMemID, string strEmail, string strQuestion, string strAnswer)
        {
            return this.dal.SecuritySettings(intMemID, strEmail, strQuestion, strAnswer);
        }

        public int SysUpdateMemIsPast()
        {
            return this.dal.SysUpdateMemIsPast();
        }

        public int Update(Chain.Model.Mem model)
        {
            int num = this.Exists(model.MemID, model.MemCard, model.MemMobile, model.MemCardNumber);
            if (num != 1)
            {
                return num;
            }
            return this.dal.Update(model);
        }

        public void UpdateLevel(int memID, int levelID)
        {
            this.dal.UpdateLevel(memID, levelID);
        }

        public int UpdateMemPastTime(int memID, DateTime pastTime)
        {
            return this.dal.UpdateMemPastTime(memID, pastTime);
        }

        public int UpdateMemPwd(int intMemID, string newPwd)
        {
            return this.dal.UpdateMemPwd(intMemID, newPwd);
        }

        public int UpdateMemPwd(int memID, string newPwd, string oldPwd)
        {
            if (oldPwd != "E62A9E6C1892C6BB")
            {
                int num = this.ExistPwd(memID, oldPwd);
                if (num != 1)
                {
                    return num;
                }
            }
            return this.dal.UpdateMemPwd(memID, newPwd);
        }

        public int UpdateMemPwd(bool isOldPwd, int memID, string newPwd, string oldPwd)
        {
            if (isOldPwd)
            {
                int num = this.ExistPwd(memID, oldPwd);
                if (num != 1)
                {
                    return num;
                }
            }
            return this.dal.UpdateMemPwd(memID, newPwd);
        }

        public int UpdateMemSelf(Chain.Model.Mem model)
        {
            int num = this.Exists(model.MemID, model.MemCard, model.MemMobile, "");
            if (num != 1)
            {
                return num;
            }
            return this.dal.UpdateMemSelf(model);
        }

        public int UpdateMemState(int memID, int state)
        {
            return this.dal.UpdateMemState(memID, state);
        }

        public int updateMemSyaArea(string strProvince, string strCity, string strCounty, string strVillage, int memId)
        {
            return this.dal.updateMemSyaArea(strProvince, strCity, strCounty, strVillage, memId);
        }

        public int UpdateMoney(int memID, decimal money)
        {
            return this.dal.UpdateMoney(money, memID);
        }

        public int UpdatePoint(int memID, int point)
        {
            return this.dal.UpdatePoint(memID, point);
        }

        public DataSet WeiXinLogin(string WeiXinCard, string PassWord)
        {
            return this.dal.WeiXinLogin(WeiXinCard, PassWord);
        }

        public int WeiXinRegister(string MemName, string PassWord, string telnumber, string referrerMemId, string memWeiXinCard, int MemShopID, string hidtf)
        {
            return this.dal.WeiXinRegister(MemName, PassWord, telnumber, referrerMemId, memWeiXinCard, MemShopID, hidtf);
        }
    }
}

